module.exports = function ($scope, $resource, $modal, toaster, str2Data) {

	//查询需要认定的审计报告
	$scope.search = function(pageNo) {
		$scope.searchform.loading = true;
		var para = {
			'pageNo': pageNo,
			'pageSize': $scope.itemsPerPage,
			'company_code': $scope.searchform.code
		}
		$resource('/api/ac/atc/auditReportService/getReportList', {}, {}).save(para, function(res){
            if (res.errcode === 0) {
				$scope.reportList = res.data.results;
				$scope.totalItems = res.data.totalRecord;
				$scope.currentPage = pageNo;
				$scope.searchform.loading = false;
            } else {
                toaster.error({title: '', body: res.errmsg});
            }
        });
	}

	//加载参加招徕奖励活动的机构名单
	$scope.loadCompany = function() {
		$resource('/api/as/atc/tourist/companySimList', {}, {}).save({}, function(res){
            if (res.errcode === 0) {
				$scope.searchform.company_list = res.data;
				$scope.searchform.company_list.unshift({'company_name': '全部', 'company_code': undefined});
            } else {
                toaster.error({title: '', body: res.errmsg});
            }
        });
	}

    init();
    function init() {
		$scope.currentPage = 1;			//当前页码
		$scope.itemsPerPage = 10;		//每页显示几条
		$scope.searchform = {};
		$scope.loadCompany();
		$scope.search(1);
		//加载完补贴规则后查询游团信息
		$resource('/api/as/atc/policy/getStandardList', {}, {}).save({}, function(res){
			if (res.errcode === 0) {
				$scope.ruleList = res.data;
				angular.forEach($scope.ruleList, function(item) {
					var index = item.subsidy_money.indexOf(',');
					if(index != -1){
						str2Data(item.subsidy_money.substring(0, index) , item);
						str2Data(item.subsidy_money.substring(index + 1) , item);
					} else {
						str2Data(item.subsidy_money, item);
					}
				});
			} else {
				toaster.error({title: '', body: '加载补贴规则失败, 请刷新页面'});
			}
		});
	};

	
	//查看补贴规则
	$scope.getSubsidyType = function() {
		var modalInstance = $modal.open({
			template: require('../views/subsidyType.html'),
			controller: 'subsidyType',
			size: 'lg',
			resolve: {
				ruleList: function () {
					return $scope.ruleList;
				}
			}
		});
	}

    //报告认定
	$scope.agree = function(item) {
		var modalInstance = $modal.open({
			template: require('../views/confirmReport.html'),
			controller: 'confirmReport',
			size: 'lg',
			resolve: {
				item: function () {
					return item;
				},
				auditFlag: function () {
					return true;
				}
			}
		});
		//关闭模态框刷新页面
		modalInstance.result.then(function(result) {
			$scope.search();
		});
	};
	
    //查看
	$scope.getInfo = function(item) {
		var modalInstance = $modal.open({
			template: require('../views/confirmReport.html'),
			controller: 'confirmReport',
			size: 'lg',
			resolve: {
				item: function () {
					return item;
				},
				auditFlag: function () {
					return false;
				}
			}
		});
    };


};